//
//  Common.swift
//  FZSina_Swift
//
//  Created by 李忠 on 7/20/16.
//  Copyright © 2016 FZLZ. All rights reserved.
//

import UIKit

//APP主题颜色
let ThemColor: UIColor = UIColor.orangeColor()

let TheColor: UIColor = UIColor.init(white: 237, alpha: 1.0)

//新浪微博ID
let sinaMaxID = "FZsinaMaxID"


//新浪APP信息
let APPKEY: String = "827828210"
let APPSECRET: String = "190a247f26d3509852c812928f46310f"
//新浪授权地址
let AUTHORIZATION: String = "https://api.weibo.com/oauth2/authorize?client_id=\(APPKEY)&redirect_uri=\(APPREDIRECT_URI)"
//回调页面
let APPREDIRECT_URI: String = "http://www.baidu.com/"

//屏幕宽高
let SCREENW = UIScreen.mainScreen().bounds.width
let SCREENH = UIScreen.mainScreen().bounds.height

//用于发送通知的消息
let FZSWITCHROOTVIEWCONTROLLER = "FZSWITCHROOTVIEWCONTROLLER"
//用于删除文本按钮发出的通知
let FZDELETEEMOTICONBUTTONNOTI = "FZDELETEEMOTICONBUTTONNOTI"
//用于输入表情
let FZINPUTEMOTICONNOTI = "FZINPUTEMOTICONNOTI"

//版本关键字
let FZAPPVERSION = "FZAppVersion"

//约束的参照数
let PADDING: CGFloat = 10.0

//得到东八区的时间
let CURRENTDATE =  NSDate().dateByAddingTimeInterval(NSTimeInterval(NSTimeZone.systemTimeZone().secondsFromGMTForDate(NSDate())))

let TheTableColor = UIColor.groupTableViewBackgroundColor()

//三基色
func RGB(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat = 1.0) -> UIColor {
    return UIColor.init(red: red, green: green, blue: blue, alpha: alpha)
}
//随机色
func RANDRGB() -> UIColor{

    let r = arc4random_uniform(256)
    let g = arc4random_uniform(256)
    let b = arc4random_uniform(256)
    return UIColor.init(red: CGFloat(r) / 255, green: CGFloat(g) / 255, blue: CGFloat(b) / 255, alpha: 1.0)
}

func formatedTime(timeString: String) -> String {
    
    let format = NSDateFormatter()
    format.dateFormat = "EEE MMM dd HH:mm:ss Z yyyy"
    
    format.locale = NSLocale(localeIdentifier:"en_US")
    let dt = format.dateFromString(timeString)
    
    guard let date = dt else{
        return timeString
    }
    
    /// 与当前类比的日期格式
    let calendar = NSCalendar.currentCalendar()
    //年份
    var dc = calendar.components(NSCalendarUnit.Year, fromDate: date, toDate: NSDate(), options: NSCalendarOptions.WrapComponents)
     var curTime = dc.year
    if curTime != 0 {
        format.dateFormat = "yyyy年MM月dd日 HH:mm"
        let time = format.stringFromDate(date)
        return "\(time)"
    }
    
    //分钟之前
    dc = calendar.components(NSCalendarUnit.Minute, fromDate: date, toDate: NSDate(), options: NSCalendarOptions.WrapComponents)
    
    curTime = dc.minute
    
    if curTime < 10 {
        return "刚刚"
    }
    if curTime < 60 {
        return "\(curTime)分钟之前"
    }
    //小时之前
    dc = calendar.components(NSCalendarUnit.Hour, fromDate: date, toDate: NSDate(), options: NSCalendarOptions.WrapComponents)
    curTime = dc.hour
    if  curTime < 24 {
        return "\(curTime)小时之前"
    }
    //前一天
    if curTime >= 24 && curTime < 48 {
        
        format.dateFormat = "HH:mm"
        let time = format.stringFromDate(date)
        return "昨天 \(time)"
    }
    format.dateFormat = "MM-dd"
    return format.stringFromDate(date)
}